package com.yoda.mall.admin.service;


import cn.hutool.core.convert.Convert;
import com.yoda.mall.api.ResourceApi;
import com.yoda.mall.model.entity.ums.Resource;
import com.yoda.mall.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResourceService {
    @DubboReference
    private ResourceApi resourceApi;

    public List<Resource> listAll() {
        return  resourceApi.listAll();
    }

    public PageResult<Resource> list(Integer categoryId, String nameKeyword, String urlKeyword, Integer pageNum, Integer pageSize) {
        return resourceApi.pageList(categoryId,nameKeyword,urlKeyword,pageNum,pageSize);
    }

    public void create(Resource resource) {
        resourceApi.create(resource);
    }

    public void delete(Integer id) {
        resourceApi.deleteById(id);
    }

    public void update(Integer id, Resource resource) {
        resource.setId(Convert.toLong(id));
        resourceApi.updateById(resource);
    }

    public Resource info(Integer id) {
        return resourceApi.findById(id);
    }
}
